﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MVCSG.Context;
using MVCSG.Models;

namespace MVCSG.Controllers
{
    public class ProductsController : Controller
    {
        private StoreContext db = new StoreContext();
        //
        // GET: /Products/

        public ActionResult Index()
        {
            return View(db.Product.ToList());
        }
        [HttpGet]
        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Create(Products product)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    db.Product.Add(product);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
                return View(product);
            }
            catch 
            {
                return View(product);
            }
        }
    }
}
